package com.springboot.bookmanegersystem.config;

import com.springboot.bookmanegersystem.interceptor.IdentityInterceptor;
import com.springboot.bookmanegersystem.interceptor.LoginInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA.
 * Description :
 * User: jiume
 * Date: 2025-05-12
 * Time: 19:18
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;

    @Resource
    private IdentityInterceptor identityInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器并配置拦截器的拦截路径

        // 注册登录拦截器: 拦截所有未登录的用户
        registry.addInterceptor(loginInterceptor).addPathPatterns("/book/*");

        // 注册身份拦截器: 拦截所有普通用户
        registry.addInterceptor(identityInterceptor)
                .addPathPatterns("/book/deleteBook")
                .addPathPatterns("/book/updateBook")
                .addPathPatterns("/book/addBook")
                .addPathPatterns("/book/batchDeleteBook");
    }
}
